package main.model;

import y.base.Node;

/**
 * a pair of nodes in an ontology. It is used for computing the posterior probability of a
 * potential edge of the ontology given a path. A potential edge in the ontology is a pair of 
 * nodes including attribute nodes or relationship (edges).
 * 
 * @author YuanAn
 *
 */
public class OntoNodePair implements OntoEle {
	private OntoEle first;
	private OntoEle second;
	private String name;
	
	//record the corresponding node objects too
	private Node firstNode;
	private Node secondNode;
	
	/**
	 * This constructor creates a dummy pair representing all the other potential edges
	 * in the ontology
	 * 
	 */
	public OntoNodePair(){
		first = second = null;
		
		firstNode = secondNode = null;
		
		name = "#Dummy Edge#"; 
	}
	
	public OntoNodePair(OntoEle f, OntoEle s){
		first = f;
		second = s;
		
		makeName();
	}

	public void setFirstNode(Node first){
		firstNode = first;
	}
	
	public void setSecondNode(Node second){
		secondNode = second;
	}
	
	public Node getFirstNode(){
		return firstNode;
	}
	
	public Node getSecondNode(){
		return secondNode;
	}
	
	private void makeName(){
		name = "";
		
		String firstName = "";
		String secondName = "";
		
		if(first instanceof Attribute || first instanceof Relationship)
			firstName = "<" + first.getName() + ">";
		else 
			firstName = "[" + first.getName() + "]";
		
		if(second instanceof Attribute || second instanceof Relationship)
			secondName = "<" + second.getName() + ">";
		else 
			secondName = "[" + second.getName() + "]";
		
		name += firstName + "++" + secondName;
		
	}
	
	/**
	 * a dummy pair if both nodes are null.
	 * @return
	 */
	public boolean isDummy(){
		
		return (first == null && second == null);
		
	}
	
	/**
	 * return true if this pair is the same as the other pair
	 * @param other
	 * @return
	 */
	public boolean isSame(OntoNodePair other){
		
		if(this.isDummy() || other.isDummy())
			return false;
		
		
		return (this.first == other.first && this.second == other.second);
	}
	
	@Override
	public String getName() {
		// TODO Auto-generated method stub		
		
		return name;
	}

	@Override
	public String display() {
		// TODO Auto-generated method stub
		
		return name;
	}

}
